package com.hdd.admin.qiniu;
import com.alibaba.fastjson.JSONObject;
import com.hdd.config.Constant;
import com.hdd.dto.SuperRequest;
import com.hdd.dto.SuperResponse;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
/**
 * @author fang
 * @date 2019/10/15 18:09
 **/
@CrossOrigin(maxAge = 3600)
@RestController
@Api(value = "后台-七牛相关接口" ,description ="后台-七牛相关接口")
@RequestMapping("/web/upload/")
public class QiniuController {

    private Auth auth = null;
    private Configuration configuration = new Configuration();


//    /**
//     * 七牛文档地址
//     * https://developer.qiniu.com/kodo/manual/1272/form-upload
//     */
//

    @ResponseBody
    @ApiOperation(value="获取后台图片上传token √", notes="")
    @RequestMapping(value = "/getWebUploadToken", method = RequestMethod.POST)
    public SuperResponse getWebUploadToken(@RequestBody SuperRequest request) {
        SuperResponse response = new SuperResponse();
        auth = Auth.create(Constant.ACCESS_KEY, Constant.SECRET_KEY);
        response.setToken(auth.uploadToken(Constant.bucket_web));
        UploadManager uploadManager = new UploadManager(configuration);

        return response;
    }

}
